package flexo.examples;

import flexo.graphic.Color;
import flexo.input.Event;
import flexo.math.Vector;

public class Test_Graphic_Gui extends Test_Graphic_Base implements flexo.input.EventListener
{
	flexo.scene.Node root;
	flexo.scene.Node gridNode;
	
	flexo.graphic.Camera guiCam;
	int layout = 1;
	
	public static void main(String[] args)
	{		
		run("flexo.examples.Test_Graphic_Gui");
	}
	
	public void init()
	{
		super.init();
		
		root = mainScene.addChild("root");
		root.setPosition(new Vector(0,0,0));
		
		gridNode = root.addChild("grid");
		
		flexo.graphic.Material mat = graphic.addMaterial("gridMat", "textureRepeat");
		flexo.graphic.ShaderParam param = mat.getShaderParam("tex");
		param.setValue("textures/grid.png");
		param = mat.getShaderParam("repeatU");
		param.setValue(50.0f);
		param = mat.getShaderParam("repeatV");
		param.setValue(50.0f);
		
		flexo.graphic.entity.Entity grid = graphic.addQuad(50, 50);
		grid.setMaterial("gridMat");
		grid.attachTo(gridNode);
		gridNode.setRotation(new flexo.math.Quaternion(new flexo.math.Vector(1,0,0),-90.0f));
		gridNode.setPosition(new flexo.math.Vector(0,-3,0));
		
		// Remove the mouse looking thing
		this.fpsLook.remove();
		
		input.addEventListener(this);
		input.addAction("ChangeLayout", flexo.input.EventType.KEY_SPACE);
		
		// GUI Creation
		gui.addTheme(new flexo.gui.flat.Theme("flatGreen",Color.GRAY,Color.BLACK,Color.BLACK,Color.GREEN,Color.WHITE));
		
		//gui.addLayout(1, "media/gui/emptyLayout.xml");
		gui.addLayout(1, "media/gui/testLayout.xml");
		
		gui.setDefaultTheme("flatGreen");
		
		gui.addLayout(2, "media/gui/logoLayout.xml");
		gui.setCursorSensitivity(30);				
	}

	public void cleanUp()
	{
	}	

	public void update()
	{		
	}

	@Override
	public void processEvent(Event e)
	{
		if (e.check("ChangeLayout") && e.getValue() > 0)
		{
			gui.setActiveLayout(layout);
			++layout;
			if (layout > 2)
			{
				layout = 1;
			}
		}
	}
}
